package com.sw.chinesewriteboard.copybook;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;

import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ToastUtils;
import com.sw.chinesewriteboard.model.MyData;
import com.sw.chinesewriteboard.view.CustomProgressDialog;

import java.io.File;
import java.util.List;

/**
 * @Description:
 * @author: GordenGao
 * @Email: gordengao124@gmail.com
 * @date: 2021年06月23日 16:18
 */
public abstract class CopybookActivity extends Activity {

    protected String SAVEDIR = "";
    protected String picName = "";
    protected ToastUtils toastUtils;
    private CustomProgressDialog loadingDialog;


    protected abstract MyData getData();

    protected abstract List<String> getListContent();

    protected abstract void refreshCopyBookView();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        picName = System.currentTimeMillis() + ".png";
        SAVEDIR = getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() + File.separator + picName;

        toastUtils = new ToastUtils()
                .setGravity(Gravity.CENTER, 0, 0)
                .setMode(ToastUtils.MODE.LIGHT);
    }

    /**
     * 显示系统等待框
     */
    public void showLoadingDialog() {
        if (loadingDialog == null) {
            loadingDialog = new CustomProgressDialog(this);
            loadingDialog.setCancelable(false);
        }
        if (!loadingDialog.isShowing()) {
            loadingDialog.show();
        }
    }

    /**
     * 显示系统等待框
     */
    public void showLoadingDialog(String tips) {
        if (loadingDialog == null) {
            loadingDialog = new CustomProgressDialog(this, tips);
            loadingDialog.setCancelable(false);
        }
        if (!loadingDialog.isShowing()) {
            loadingDialog.show();
        }
    }

    /**
     * 显示系统等待框
     */
    public void showLoadingDialog(String msg, boolean isShowProgress) {
        if (loadingDialog == null) {
            loadingDialog = new CustomProgressDialog(this, msg, isShowProgress);
            loadingDialog.setCancelable(false);
        }
        if (!loadingDialog.isShowing()) {
            loadingDialog.show();
        }

    }

    /**
     * 关闭等待框
     */
    public void hideLoadingDialog() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }
}
